package org.firebug.spring.boot.metadata.service;

import org.firebug.common.tools.core.BeanTools;
import org.firebug.spring.boot.metadata.api.vo.DictionarySaveVO;
import org.firebug.spring.boot.metadata.api.vo.DictionaryVO;
import org.firebug.spring.boot.metadata.repository.dao.DictionaryDAO;
import org.firebug.spring.boot.metadata.repository.po.DictionaryPO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 地区服务
 */
@Service
public class DictionaryService {
    @Resource
    private DictionaryDAO dictionaryDAO;

    public void save(DictionarySaveVO vo) {
        DictionaryPO po = BeanTools.copyProperties(vo, new DictionaryPO());
        dictionaryDAO.insert(po);
    }

    public DictionaryVO queryByCode(String code) {
        DictionaryPO po = dictionaryDAO.selectByCode(code);
        return BeanTools.copyProperties(po, DictionaryVO.class, null);
    }

    public List<DictionaryVO> listByPcode(String pcode) {
        List<DictionaryPO> pos = dictionaryDAO.selectByPcode(pcode);
        return BeanTools.copyProperties(pos, new ArrayList<>(pos.size()), DictionaryVO.class);
    }

    public List<DictionaryVO> listByCodeSector(String pcode, int sector) {
        List<DictionaryPO> pos = dictionaryDAO.selectByPcodeSector(pcode, sector);
        return BeanTools.copyProperties(pos, new ArrayList<>(pos.size()), DictionaryVO.class);
    }
}